import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class VersionServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // super.doGet(req, resp);
        String curVer = req.getParameter("curVer");
        String updateType = req.getParameter("updateType");

        resp.setContentType("text/json;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        Version version = new Version();

        version.ios = new Version.Ios();
        version.ios.version = "2.0.0";
        version.ios.title = "更新";
        version.ios.note = "部分优化";
        version.ios.url = "http://www.gogo.com";

        version.android = new Version.Android();
        version.android.version = "2.0.0";
        version.android.title = "版本更新";
        version.android.note = "\"修复轮播组件和原生滚动冲突的bug； 修复列表控件不显示上边框的bug";


        switch (Integer.parseInt(updateType)) {
            case 1://整包
                version.android.url = "http://192.168.62.106:8080/app?updateType=1";
                break;
            case 2://应用资源升级
                version.android.url = "http://192.168.62.106:8080/app?updateType=2";
                break;
            case 3://应用资源差量升级
                version.android.url = "http://192.168.62.106:8080/app?updateType=3";
                break;
        }

        out.print(new Gson().toJson(version));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        resp.setContentType("text/javascript;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        out.println("post: result none");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("init");
    }
}
